package com.ruoyi.xiaoshou.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.xiaoshou.domain.SaleOrderDetail;
import com.ruoyi.xiaoshou.service.SaleOrderDetailService;
import com.ruoyi.xiaoshou.service.impl.SaleOrderDetailServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/saleOrderDetail")
public class SaleOrderDetailController {

    @Autowired
    private SaleOrderDetailService saleOrderDetailService;

    private Logger logger = LoggerFactory.getLogger(SaleOrderDetailController.class);

    /**
     * 获取所有销售订单详情
     * @param orderId
     * @return
     */
    @RequiresPermissions("xiaoshou:detail:saleOrderDetailList")
    @GetMapping(value = "/{orderId}")
    public AjaxResult list(@PathVariable("orderId") int orderId)
    {
        logger.info("SaleOrderDetailController   list start......orderId:"+orderId);
        return AjaxResult.success(saleOrderDetailService.getList(orderId));
    }
    /**
     * 出库时修改销售订单详情出库数
     */
    @RequiresPermissions("xiaoshou:detail:update")
    @PostMapping("update")
    public int update(@RequestBody SaleOrderDetail saleOrderDetail){
        return saleOrderDetailService.updDetailStock(saleOrderDetail);
    }
    @PostMapping("getSaleOrderDetail")
    public R<List<SaleOrderDetail>> getSaleOrderDetail(@RequestBody Integer orderId){
        logger.info("SaleOrderDetailController getSaleOrderDetail params:{}",orderId);
        List<SaleOrderDetail> saleOrderDetails = saleOrderDetailService.getSaleOrderDetailListByOrderId(orderId);
        return R.ok(saleOrderDetails);
    }
    @PostMapping("getSaleOrderDetailByProIdAndOrderId")
    public SaleOrderDetail getSaleOrderDetailByProIdAndOrderId(@RequestBody SaleOrderDetail saleOrderDetail){
        logger.info("SaleOrderDetailController getSaleOrderDetailByProIdAndOrderId params:{}",saleOrderDetail);
        SaleOrderDetail saleOrderDetail1 = saleOrderDetailService.getSaleOrderDetailByProIdAndOrderId(saleOrderDetail);
        return saleOrderDetail1;
    }
}
